package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.contact.pojo.dto.ContactDeleteBatchDTO;
import com.xbongbong.pro.contact.pojo.dto.ContactEditAttrUpdateDTO;
import com.xbongbong.pro.contact.pojo.dto.ContactUpdateBatchDTO;
import com.xbongbong.pro.contact.pojo.dto.ContactUpdateByBusinessRuleDTO;
import com.xbongbong.pro.contact.pojo.vo.ContactDeleteBatchVO;
import com.xbongbong.pro.contact.pojo.vo.ContactUpdateBatchVO;
import com.xbongbong.pro.contact.pojo.vo.ContactUpdateByBusinessRuleVO;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.customer.pojo.dto.CustomerRestoreBatchDTO;
import com.xbongbong.pro.form.pojo.dto.ContactDataRepeatDTO;
import com.xbongbong.pro.formdata.pojo.AfterSavePojo;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.saas.domain.entity.ext.ContactEntityExt;
import com.xbongbong.saas.domain.entity.ext.CustomerEntityExt;
import com.xbongbong.sys.domain.entity.UserEntity;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/18
 * @since v1.0
 */
public interface ContactService {
    /**
     * 联系人保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/18
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 联系人保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author feng.zheng
     */
    AfterSavePojo afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    /**
     * 联系人电话是否重复，true表示重复
     *
     * @param contactDataRepeatDTO 联系人查重入参
     * @author feng.zheng
     * @return boolean
     * @throws XbbException 业务异常
     * @date 2019/1/28 17:19
     */
    boolean contactRepeat(ContactDataRepeatDTO contactDataRepeatDTO) throws XbbException;

    /**
     * 更新客户名称
     * @author 吴峰
     * @date 15:42 2019/2/15
     * @desrcption
     * @param contactUpdateBatchDTO 客户名称更新入参
     * @return void
     * @throws XbbException 业务异常
    */
    ContactUpdateBatchVO updateBatch(ContactUpdateBatchDTO contactUpdateBatchDTO) throws XbbException;

    /**
     * 更新客户名称
     * @author 吴峰
     * @date 15:42 2019/2/15
     * @desrcption
     * @param contactUpdateBatchDTO 客户名称更新入参
     * @return void
     * @throws XbbException 业务异常
     */
    ContactUpdateBatchVO updateBatch(ContactUpdateBatchDTO contactUpdateBatchDTO, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 根据业务规则修改数据
     * @param contactUpdateByBusinessRuleDTO
     * @throws XbbException
     * @return
     */
    ContactUpdateByBusinessRuleVO updateFormDataByBusinessRule(ContactUpdateByBusinessRuleDTO contactUpdateByBusinessRuleDTO) throws XbbException;

    /**
     * 根据联系人id队列查找符合要求的联系人列表
     * @param corpid 公司id
     * @param contactIds 联系人id队列
     * @return List 联系人列表
     * @author youli.chen
     * @throws XbbException
     */
    List<ContactEntityExt> getContactListByIds(String corpid, List<Long> contactIds) throws XbbException;

    /**
     * 批量删除
     * @author 吴峰
     * @date 2019/3/10 15:55
     * @param contactDeleteBatchDTO
     * @return com.xbongbong.pro.contact.pojo.vo.ContactDeleteBatchVO
     * @throws XbbException 业务异常
     */
    ContactDeleteBatchVO deleteBatch(ContactDeleteBatchDTO contactDeleteBatchDTO) throws XbbException;

    /**
     * 格式化移动端列表页
     *
     * @param formDataListDTO 用户
     * @param esEntities 业务实体集合
     * @param totalCount 总数
     * @return ListAppVO
     * @throws XbbException
     * @author long.rao
     * @date 2019-03-11 13:50
     */
    ListAppVO formatContactAppList(FormDataListDTO formDataListDTO, List<PaasFormDataEntityExt> esEntities, Integer totalCount) throws XbbException;

    /**
     * 关联新建时格式化解释
     *
     * @param handlerExplainInLinkItemDTO 入参
     * @throws XbbException 异常
     * @author feng.zheng
     * @date 2019-03-16 20:53
     */
    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;

    /**
     * 批量更新某个字段
     * @author 吴峰
     * @date 2019/3/18 22:24
     * @param contactEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(ContactEditAttrUpdateDTO contactEditAttrUpdateDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     * @author feng.zheng
     * @date 2019/4/29 14:16
     * @since V1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * Description: 一致性同步
     * @param corpid
     * @param customerId
     * @param customerName
     * @return void
     * @throws
     * @author 魏荣杰
     * @date 2019/6/12 9:45
     * @since v1.0
     */
    void dataConsistencyUpdateCustomer(String corpid, Long customerId, String customerName) throws XbbException;

    /**
     * 详情页用的
     *
     * @param saasAnalysisDataDTO
     * @param result
     * @throws XbbException
     */
    void getFormatData(SaasAnalysisDataDTO saasAnalysisDataDTO, JSONObject result) throws XbbException;

    /**
     * 更新回滚
     * @param idIn
     * @param corpid
     * @throws XbbException
     */
    void updateRollback(List<Long> idIn, String corpid) throws XbbException;

    void addBatchForImport(List<ValidateDataDTO> needAddList, CustomerEntityExt customerEntityExt, Map<String, UserEntity> userMap, FormDataAddDTO formDataAddDTO) throws XbbException;

    /**
     * 还原数据
     * @author xingxing.xiao
     */
    void restoreBatch(String corpid, Map<Long, Long> customerUpdateTimeMap, CustomerRestoreBatchDTO customerRestoreBatchDTO) throws XbbException;

    /**
     * 批量修改标签
     * @param addLabelDTO
     * @param addBatchList
     * @throws XbbException
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    /**
     * user关联到客户对应的所有联系人上（用于客户新建联系人以及删除联系人）
     * @param customerId
     * @param contactId
     * @param corpid
     * @throws XbbException
     */
    void userRelateCustomerContact(Long customerId, Long contactId, String corpid) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;
}
